/**
 * Copyright (C)  2011  chen wei hua.
 * Permission is granted to copy, distribute and/or modify this document
 * under the terms of the GNU Free Documentation License, Version 2.0
 * or any later version published by the Free Software Foundation;
 * with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
 * A copy of the license is included in the section entitled "GNU Free Documentation License".
 */
package com.javaeye.chenweihuacwh.web.orderManage;

import java.util.List;
import java.util.Set;

import com.javaeye.chenweihuacwh.dto.orderManage.CustomerOrder;
import com.javaeye.chenweihuacwh.dto.orderManage.OrderDetail;
import com.javaeye.chenweihuacwh.service.orderManage.IOrderService;

public class InStoreAction extends OrderAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7408989332825417843L;

	private List<Integer> instoreNumbers;
	
	/**
	 * 查询需要入库的出货单列表
	 * @return
	 * @throws Exception
	 */
	public String queryInStoreList() throws Exception {
		getCondition().setStatus(new Object[]{IOrderService.ORDER_STATES_BUSINESS});
		return queryOrderList();
	}
	
	/**
	 * 查询用于入库
	 * @return
	 * @throws Exception
	 */
	public String queryOrderInStore() throws Exception {
		return queryOrderBaseInfo();
	}
	
	/**
	 * 保存入库数量
	 * @return
	 * @throws Exception
	 */
	public String saveOrderInStore() throws Exception {
		CustomerOrder order = getService().getOrderBaseInfo(getOrderId());
		Set<OrderDetail> details = order.getOrderDetails();
		int index = 0;
		for (OrderDetail detail : details) {
			detail.setInStoreNumber(instoreNumbers.get(index));
			index++;
		}
		getService().saveOrder(order);
		return SUCCESS;
	}

	public List<Integer> getInstoreNumbers() {
		return instoreNumbers;
	}

	public void setInstoreNumbers(List<Integer> instoreNumbers) {
		this.instoreNumbers = instoreNumbers;
	}
	
}
